<?php

namespace App\Models;



use Illuminate\Http\Exceptions\HttpResponseException;

class Payment extends ApiBaseModel
{
    protected $table = 'mp_payment';
    protected $fillable = [
        'payment_code',
        'payment_name',
        'user_id',
        'is_default',
        'status',
        'setting',
        'callback_url',
        'pay_rate',
        'create_by',
        'update_by',
        'file_path',
        'is_body',
        'pay_appid',
    ];
    protected $casts = [];


    // public function registerGlobalScopes($builder)
    // {
    //     foreach ($this->getGlobalScopes() as $identifier => $scope) {
    //         $builder->withGlobalScope($identifier, $scope);
    //     }

    //     $builder->where('pay_status', '=', 1);

    //     return $builder;
    // }
    public function user()
    {
        return $this->belongsTo(SysUser::class, 'user_id', 'id');
    }
    public function getSettingAttribute($value)
    {
        return json_decode($value, true);
    }
    public function setSettingAttribute($value)
    {
        $this->attributes['setting'] = json_encode($value);
    }
    public function getCallbackUrlAttribute($value)
    {
        // return $value . "111";
        return env('APP_URL') . "/api/payCallbackV2/" . $this->attributes['payment_code'] . '/' . $this->attributes['id'];
    }
}
